package com.cby.leetcode.滑动窗口.LC209;

import java.util.Map;

/**
 * ClassName: LC209
 * Package: com.cby.leetcode.滑动窗口.LC209
 * Description:
 *
 * @Author dhu-bion
 * @Create 2025/9/10 15:31
 * @Version 1.0
 */
public class LC209 {

    public static void main(String[] args){}

    static class Solution{
        public int minSubArrayLen(int target, int[] nums) {
            int res = nums.length + 1;
            int sum = 0;
            int left = 0;

            //1，枚举右端点
            for(int right = 0; right < nums.length; right ++){
                sum += nums[right];
                while(sum >= target){
                    //2.枚举左端点
                    res = Math.min(right - left + 1, res);
                    sum -= nums[left];
                    left ++;
                }
            }

            return res == nums.length + 1 ? 0 : res;
        }
    }


}
